package com.lcj.controller;

import com.lcj.dto.UserInfoReg;
import com.lcj.dto.UserLogin;
import com.lcj.dto.UserReg;
import com.lcj.dto.UserUpdate;
import com.lcj.entity.Users;
import com.lcj.rsp.ApiResponse;
import com.lcj.service.IUserService;
import com.lcj.service.impl.UserService;
import com.lcj.utils.UserUtils;
import com.lcj.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    IUserService iUserService;
    @Autowired
    private UserService userService;

    @PostMapping("/users")
    public ApiResponse<UserInfo> rigister(UserReg userReg) {
        UserInfo register = iUserService.register(userReg);
        return ApiResponse.success(register);
    }
    @PostMapping("/users/login")
    public ApiResponse<UserInfo>  login(UserLogin userLogin){
        UserInfo login = iUserService.login(userLogin);
        return ApiResponse.success(login);
    }
    @GetMapping("/user")
    public ApiResponse<UserInfo>  getUserInfo(@RequestHeader("Authorization") String token ){
        UserInfo userInfo = userService.getUserInfo(token);

        return ApiResponse.success(userInfo);
    }
    @PutMapping("/user")
    public ApiResponse<UserInfo>  updateUser(@RequestHeader("Authorization") String token, UserUpdate userUpdate){
        UserInfo update = userService.update(token, userUpdate);
        return ApiResponse.success(update);

    }

}
